<?php
 require("init.php");
	  @$uname=$_REQUEST["uname"];
	  @$upwd=$_REQUEST["upwd"];
	  @$utel=$_REQUEST["utel"];
	 if($uname===null || $uname===""){
     	die('{"code":-1,"msg":"用户名不能为空"}');
     	return;
     }
     if($upwd===null || $upwd===""){
     	die('{"code":-1,"msg":"密码不能为空"}');
     	return;
     }
     if($utel===null || $utel===""){
     	die('{"code":-1,"msg":"电话不能为空"}');
     	return;
     }
     $reg = '/^[a-zA-Z0-9]{3,12}$/';
     $re = '/1[34578]\d{9}$/';
     $rs = preg_match($reg,$uname);//返回1对0错
     $ms = preg_match($reg,$upwd);
     $tel = preg_match($re,$utel);
     if(!$rs){
         die('{"code":-1,"msg":"用户名格式有误，请检查"}');
         return;
     }
     if(!$ms){
         die('{"code":-1,"msg":"密码格式有误，请检查"}');
         return;
     }
     if(!$tel){
         die('{"code":-1,"msg":"电话格式有误，请检查"}');
         return;
     }
      $sql="SELECT uid FROM user WHERE uname='$uname' AND upwd=md5('$upwd')";
      $result=mysqli_query($conn,$sql);
      $row=mysqli_fetch_row($result);
         if($row!=null){
             echo'{"code":1,"msg":"注册失败用户名或密码重复"}';
         }else{
         $sql="insert into user(uname,upwd,utel) values('$uname',md5('$upwd'),'$utel')";
              $result=mysqli_query($conn,$sql);
             echo '{"code":1,"msg":"注册成功"}';
         }
?>